package statistics;

import impsoft.scripting.ibot.enums.Skill;
import base.DreamScript;

public class ExperienceHandler {
	// combat
	private static final Experience ATTACK = new Experience(Skill.ATTACK);
	private static final Experience STRENGTH = new Experience(Skill.STRENGTH);
	private static final Experience DEFENSE = new Experience(Skill.DEFENSE);
	private static final Experience MAGIC = new Experience(Skill.MAGIC);
	private static final Experience RANGING = new Experience(Skill.RANGED);
	private static final Experience HITPOINTS = new Experience(Skill.HITPOINTS);
	// skills
	private static final Experience CRAFTING = new Experience(Skill.CRAFTING);
	private static final Experience HERBLORE = new Experience(Skill.HERBLORE);
	private static final Experience AGILITY = new Experience(Skill.AGILITY);
	private static final Experience FARMING = new Experience(Skill.FARMING);

	public Experience[] getExperiences() {
		return new Experience[] { ATTACK, STRENGTH, DEFENSE, MAGIC, RANGING, HITPOINTS, CRAFTING, HERBLORE, AGILITY, FARMING };
	}

	public void startAllExperiences(DreamScript script) throws InterruptedException {
		for (Experience experience : getExperiences()) {
			startExperience(experience.getSkill(), script);
		}
	}

	public void startExperience(Skill skill, DreamScript script) throws InterruptedException {
		getExperience(skill).startTracking(script);
	}

	public Experience getExperience(Skill skill) {
		for (Experience experience : getExperiences()) {
			if (experience.getSkill().equals(skill)) {
				return experience;
			}
		}

		return null;
	}

	public long getTotalHourlyXP(DreamScript script) throws InterruptedException {
		return Experience.getHourlyXP(getTotalXPGained(), script.getTimeRan());
	}

	public long getTotalXPGained() throws InterruptedException {
		long total = 0;
		for (Experience experience : getExperiences()) {
			total += experience.getTotalXPGained();
		}

		return total;
	}
}
